package com.woniuxy.service.impl;

import com.woniuxy.entity.ShopSpecOptions;
import com.woniuxy.dao.ShopSpecOptionsDao;
import com.woniuxy.service.ShopSpecOptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.util.List;


/**
 * (ShopSpecOptions)表服务实现类
 *
 * @author makejava
 * @since 2025-07-15 14:13:34
 */
@Service("shopSpecOptionsService")
public class ShopSpecOptionsServiceImpl implements ShopSpecOptionsService {
    @Autowired
    private ShopSpecOptionsDao shopSpecOptionsDao;



    @Override
    public List<ShopSpecOptions> findById(Integer specId) {
        return shopSpecOptionsDao.findById(specId);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param optionId 主键
     * @return 实例对象
     */
    @Override
    public ShopSpecOptions queryById(Integer optionId) {
        return this.shopSpecOptionsDao.queryById(optionId);
    }

    /**
     * 分页查询
     *
     * @param shopSpecOptions 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShopSpecOptions> queryByPage(ShopSpecOptions shopSpecOptions, PageRequest pageRequest) {
        long total = this.shopSpecOptionsDao.count(shopSpecOptions);
        return new PageImpl<>(this.shopSpecOptionsDao.queryAllByLimit(shopSpecOptions, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shopSpecOptions 实例对象
     * @return 实例对象
     */
    @Override
    public ShopSpecOptions insert(ShopSpecOptions shopSpecOptions) {
        this.shopSpecOptionsDao.insert(shopSpecOptions);
        return shopSpecOptions;
    }

    /**
     * 修改数据
     *
     * @param shopSpecOptions 实例对象
     * @return 实例对象
     */
    @Override
    public ShopSpecOptions update(ShopSpecOptions shopSpecOptions) {
        this.shopSpecOptionsDao.update(shopSpecOptions);
        return this.queryById(shopSpecOptions.getOptionId());
    }

    /**
     * 通过主键删除数据
     *
     * @param optionId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer optionId) {
        return this.shopSpecOptionsDao.deleteById(optionId) > 0;
    }
}
